package com.example.ythhome.login.api;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.ythhome.login.entity.*;
import com.example.ythhome.login.service.UserService;
import com.example.ythhome.person.entity.HomePersonPo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("api/login")
public class LoginController {
    @Autowired
    UserService userService;



    @GetMapping("/login/{username}/{password}")
    @ResponseBody
    public LoginMsg login1(@PathVariable("username") String username, @PathVariable("password") String password){
        LoginMsg loginMsg = new LoginMsg();
        if (userService.checkUserPassword(username, password)){
            loginMsg.setSuccess(true);
            RouteData routeData = new RouteData();
            routeData.setAvatar("https://avatars.githubusercontent.com/u/44761321");
            routeData.setUsername("admin");
            routeData.setNickname("小铭aaa");
            List<String> roles = new ArrayList<>();
            roles.add("admin");
            routeData.setRoles(roles);
            List<String> permissions = new ArrayList<>();
            permissions.add("*:*:*");
            routeData.setPermissions(permissions);
            routeData.setAccessToken("eyJhbGciOiJIUzUxMiJ9.admin");
            routeData.setRefreshToken("eyJhbGciOiJIUzUxMiJ9.adminRefresh");
            routeData.setExpires("2030/10/30 00:00:00");
//            User.UserBuilder users = User.withDefaultPasswordEncoder();
//            UserDetails user = users.username(accountName).password(accountPwd).roles("USER","ADMIN").build();
//             new InMemoryUserDetailsManager(user);
            loginMsg.setData(routeData);
        }else {
            loginMsg.setSuccess(false);
        }
        return loginMsg;
    };

}
